package com.api;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.component.domain.MDocument;
import com.component.service.MDocumentService;
import com.system.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("document")
public class DocumentApi {

    @Autowired
    private MDocumentService mDocumentService;


    @GetMapping("/list")
    public JSONObject getJSONObject(@RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,
                                    @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize,
                                    @RequestParam(value = "keyword",required = false)String keyword){
        IPage<MDocument> mDocumentIPage=mDocumentService.page(keyword,pageNum,pageSize);
        return Result.successInfo(mDocumentIPage);
    }

    @PostMapping("add")
    public JSONObject addDocumentController(@RequestParam("file")MultipartFile file,
                                            @RequestParam(value = "note",required = false)String note){
        mDocumentService.save(file,note);
        return Result.successInfo("新增成功");
    }

    @GetMapping("delete")
    public JSONObject delete(@RequestParam("id")String id){
        mDocumentService.removeById(id);
        return Result.successInfo("删除成功");
    }
}
